package com.puzzlebazar.client.main.control;

import com.puzzlebazar.client.main.view.TabbedView;
import com.puzzlebazar.client.util.TokenFactory;

public abstract class TabbedSubstate extends NamedStateImpl implements TokenFactory {

	protected final TabbedView view;
	protected final NamedStateController controller;
	private int tabNumber;
	

	public TabbedSubstate(TabbedView view,
			NamedStateController controller) {
		super( controller );		
		
		this.view = view;
		this.controller = controller;
		
		tabNumber = view.addTab( getTabName(), this );		
	}

	/**
	 * @return The string giving the name associated with this tab
	 */
	protected abstract String getTabName(); 
	
	public String createToken() {
		return controller.buildToken(getStateName());
	}
	
	public void enter() {
		view.selectTab( tabNumber );
	}
	
	public void exit() {
		view.selectTab( -1 );
	}
	


	/**
	 * Change the visibility state of the tab attached to this substate
	 * 
	 * @param visible True to make the tab visible, false to hide it
	 */
	public void setTabVisible(boolean visible) {
		view.setTabVisible( tabNumber, visible );
	}	
	

	@Override
	public void release() {
		super.release();
	}
}
